package com.eightbears.beboy.ui.user.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.eightbears.beboy.R;
import com.eightbears.beboy.base.BaseActivity;
import com.eightbears.beboy.base.view.SwipeBackLayout;
import com.eightbears.beboy.entity.HongBaoEntity;
import com.eightbears.beboy.entity.event.RedSelectEvent;
import com.eightbears.beboy.ui.user.fragment.MoneyRedFragment;
import com.eightbears.beboy.ui.user.fragment.PostRedFragment;

import butterknife.BindColor;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.eightbears.beboy.ui.user.activity.PaymentActivity.PARAMS_RED_TYPE;
import static com.eightbears.beboy.ui.user.activity.SystemMessageActivity.PARAMS_IS_SYSTEM_MESSAGE;


/**
 * 红包页面
 */
public class RedActivity extends BaseActivity {

    @BindView(R.id.sw_shopdetail)
    SwipeBackLayout sw_shopdetail;
    @BindView(R.id.tv_tab_left_text)
    TextView tv_tab_left_text;
    @BindView(R.id.tv_tab_right_text)
    TextView tv_tab_right_text;
    @BindView(R.id.view_left_line)
    View view_left_line;
    @BindView(R.id.view_right_line)
    View view_right_line;
    @BindView(R.id.ll_tab_left)
    LinearLayout ll_tab_left;
    @BindView(R.id.ll_tab_right)
    LinearLayout ll_tab_right;

    @BindColor(R.color.text_color_fff)
    int select;
    @BindColor(R.color.transparent_99FFF)
    int unselect;
    @BindColor(R.color.text_select_color)
    int selectLine;
    @BindColor(R.color.transparent_00000)
    int unselectLine;


    private RedSelectEvent showType = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_red);
        initView();
        initData();
        initEvent();
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        tv_tab_left_text.setText("优惠红包");
        tv_tab_right_text.setText("主题红包");
    }

    @Override
    protected void initData() {

        Bundle bundle = getIntent().getExtras();
        if (null != bundle) {
            showType = (RedSelectEvent) bundle.get(PARAMS_RED_TYPE);
            if (null != showType) {
                switch (showType.getType()) {
                    case HongBaoEntity.TYPE_MONEY:
                        showLeft();
                        break;
                    case HongBaoEntity.TYPE_POST:
                        showRight();
                        break;
                }
            }
        } else {
            selectLeft();
        }
    }

    @Override
    protected void initEvent() {
        //侧滑删除实力化
        sw_shopdetail.setCallBack(new SwipeBackLayout.CallBack() {
            @Override
            public void onFinish() {
                finish();
            }
        });
    }

    @OnClick(R.id.ll_back)
    void back() {
        finish();
    }

    @OnClick(R.id.tv_tab_left_text)
    void leftMenu() {
        selectLeft();

    }

    @OnClick(R.id.tv_tab_right_text)
    void rightMenu() {
        selectRight();

    }

    private void selectLeft() {
        replaceView();
        tv_tab_left_text.setTextColor(select);
        view_left_line.setBackgroundResource(R.color.text_select_color);
        if (null != showType)
            replaceFragment(R.id.frame_container, new MoneyRedFragment(), PARAMS_RED_TYPE, showType);
        else
            replaceFragment(R.id.frame_container, new MoneyRedFragment());
    }

    private void selectRight() {
        replaceView();
        tv_tab_right_text.setTextColor(select);
        view_right_line.setBackgroundResource(R.color.text_select_color);
        if (null != showType)
            replaceFragment(R.id.frame_container, new PostRedFragment(), PARAMS_RED_TYPE, showType);
        else
            replaceFragment(R.id.frame_container, new PostRedFragment());
    }

    private void replaceView() {
        tv_tab_left_text.setTextColor(unselect);
        tv_tab_right_text.setTextColor(unselect);
        view_left_line.setBackgroundResource(unselectLine);
        view_right_line.setBackgroundResource(unselectLine);
    }

    private void showLeft() {
        ll_tab_left.setVisibility(View.VISIBLE);
        ll_tab_right.setVisibility(View.GONE);
        selectLeft();
    }

    private void showRight() {
        ll_tab_left.setVisibility(View.GONE);
        ll_tab_right.setVisibility(View.VISIBLE);
        selectRight();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


}
